<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-11-10 14:11:48
 * @LastEditors: charles
 * @LastEditTime: 2021-11-10 14:36:02
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>组件通信-插槽</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
  <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
  <div id="app"></div>
  <script type="text/babel">

    function List(props){
      return (
        <div>
          {props.children}
          <ul>
            {
              props.data.map(item => {
                return (
                  <li key={item.id}>
                    {item.name}
                    <div>
                      {
                        props.render(item) 
                      } 
                    </div>
                  </li>)
              })
            }  
          </ul>  
        </div>
      )
    }
  

    class App extends React.Component {
      constructor(props){
        super(props);
        this.state = {
          users:[
            {id:1,name:"terry",age:12},
            {id:2,name:"jacky",age:13},
          ]
        }
      }

      renderHandler(item){
        return (
          <div>
            <button onClick={()=>{alert(item.id)}}>删除</button>  
            <button >修改</button>  
          </div>
        )
      }
      render(){
        return (
          <div>
            <h2>组件通信</h2>  
            <List 
              data={this.state.users} 
              render={this.renderHandler}>
              <h3>用户列表</h3>  
            </List>
          </div>
        )
      }
    }
    ReactDOM.render(<App/>,document.getElementById('app'));
  </script>
</body>
</html>
